//动态路由
import 'package:enjoy_plus_flutter_7/pages/login/login_page.dart';
import 'package:enjoy_plus_flutter_7/pages/notfiy/noticedetail.dart';
import 'package:enjoy_plus_flutter_7/pages/tabbar_page.dart';
import 'package:flutter/material.dart';

import '../pages/404.dart';
import '../pages/house/building_list.dart';
import '../pages/house/house_form.dart';
import '../pages/house/house_list.dart';
import '../pages/house/location_list.dart';
import '../pages/house/room_list.dart';
import '../pages/profile/profile_page.dart';
import '../utils/TokenManager.dart';

//静态路由
Map<String, Widget Function(BuildContext)> routes = {
  '/': (context) => const TabbarPage(), //根页面
  'notfiy-detail': (context) => const NoticeDetail(),
  'login': (context) => const LoginPage(),
  // 'profile': (context) => ProfilePage(),
};
//动态路由
Route<dynamic>? onGenerateRoute(RouteSettings settings) {
  String token = tokenManager.getToken();
  // print((settings.arguments as Map<String, dynamic>)['point']);
  // print((settings.arguments as Map<String, dynamic>)['building']);
  if (token != '') {
    if (settings.name == 'profile') {
      return MaterialPageRoute(
          builder: (BuildContext ctx) => ProfilePage(
              userInfo: settings.arguments as Map<String, dynamic>));
    } else if (settings.name == 'house') {
      return MaterialPageRoute(
          settings: settings, builder: (BuildContext ctx) => const HouseList());
    } else if (settings.name == 'addHouse') {
      return MaterialPageRoute(builder: (context) => const LocationList());
    } else if (settings.name == 'building_list') {
      return MaterialPageRoute(
        builder: (context) {
          return BuildingList(
            point: (settings.arguments as Map<String, dynamic>)['point'],
          );
        },
      );
    } else if (settings.name == 'room_list') {
      // print((settings.arguments as Map<String, dynamic>));
      // print((settings.arguments as Map<String, dynamic>)['building']);
      return MaterialPageRoute(
        // builder: (context) => Text('add'),
        builder: (context) => RoomList(
          point: (settings.arguments as Map<String, dynamic>)['point'],
          building: (settings.arguments as Map<String, dynamic>)['building'],
        ),
      );
    } else if (settings.name == 'house_form') {
      return MaterialPageRoute(
        // builder: (context) => Text('add'),
        builder: (context) =>
            HouseForm(params: settings.arguments as Map<String, dynamic>),
      );
    } else {
      return MaterialPageRoute(builder: (BuildContext ctx) {
        return const NotFound();
      });
    }
  } else {
    return MaterialPageRoute(builder: (BuildContext ctx) => const LoginPage());
  }
}
